[LegacyColorValue = true]; 

Vars:ExpDate(1201231);
{
Copyright (c) 1996 Stuart Okorofsky
}

Inputs:Proj(0),Price(close),MA_Type(1),MALen1(13),MALen2(55),Smooth(3),
           Delay1(1),Delay2(1),Factor1(1),Factor2(1);
{***Note - Proj is  a % of the length of the MA Length, 
     rounded to the nearest whole number.  This is how namy
     bars to the right to shift the plot}

Vars:ThisPrice(0),Avg1(0),Avg2(0),MoveLine1(0),MoveLine2(0),
       MAFactor1(0),MAFactor2(0),PlotOffset1(0),PlotOffset2(0),
       XAverageVal1(0),XAverageVal2(0);

{
MA_Type
1 - Simple
2 - Smooth
3 - EXP
4 - Weighted
5 - Centered
}

if date < ExpDate and CurrentDate <  ExpDate then BEGIN

if Barnumber = 1 and Proj > 0 then
begin  {**Need to set up for projection of lines to the right***}
     MoveLine1 = IntPortion(.5+Proj*MALen1);
     MoveLine2 = IntPortion(.5+Proj*MALen2);
end;
if barnumber = 1 and MA_Type = 5 then 
begin
     PlotOffset1 = IntPortion(MALen1/2+1);
     PlotOffset2 = IntPortion(MALen2/2+1);
end;

ThisPrice = Price;

if MA_Type = 1 or MA_Type = 5 then 
begin 
    Avg1 = Average(ThisPrice,MALen1);
    Avg2 = Average(ThisPrice,MALen2);
end;
if MA_Type = 2 then 
begin
     Avg1 = Average(Average(ThisPrice,MALen1),Smooth);
     Avg2 = Average(Average(ThisPrice,MALen2),Smooth);
end;
if MA_Type = 3 then
begin  {***Calculate EXP Average here***}
     If MALen1 + 1 <> 0 and MALen2 + 1 <> 0 then 
     begin
          If CurrentBar = 1 then 
          begin
               MAFactor1 = 2 / (MALen1 + 1);
               MAFactor2 = 2 / (MALen2 + 1);
               XAverageVal1 = ThisPrice;
               XAverageVal2 = ThisPrice;
               Avg1 = ThisPrice;
               Avg2 = ThisPrice;
          end
      Else  
          begin         
                XAverageVal1 = MAFactor1 * ThisPrice + (1 - MAFactor1) * XAverageVal1[1];
                XAverageVal2 = MAFactor2 * ThisPrice + (1 - MAFactor2) * XAverageVal2[1];                 
          end;
      end;
      Avg1 = XAverageVal1;
      Avg2  = XAverageVal2;
end; 
if MA_Type = 4 then
begin 
     Avg1  = WAverage(ThisPrice,MALen1);
     Avg2  = WAverage(ThisPrice,MALen2);
end;

{****Adjust prices if necessary*****}
Avg1 = Avg1*Factor1;
Avg2 = Avg2*Factor2;

if MoveLine1= 0 and barnumber > Maxlist(MaLen1,MaLen2) then
begin  {***Plot current values***}
     if Avg1 > Avg1[Delay1] 
          then plot1[PlotOffset1](Avg1,"MA1_UP")
          else plot2[PlotOffset1](Avg1,"MA1_DN");
end
else
begin  {***Plot Previous values***}
     if  barnumber > Maxlist(MaLen1,MaLen2) then
     begin
         if Avg1[MoveLine1] > Avg1[Delay1+MoveLine1] 
              then plot1(Avg1[MoveLine1],"MA1_UP")
              else plot2(Avg1[MoveLine1],"MA1_DN");
     end;
end;

if MoveLine2= 0 and barnumber > Maxlist(MaLen1,MaLen2) then
begin  {***Plot current values***}
     if Avg2 > Avg2[Delay2] 
          then plot3[PlotOffset2](Avg2,"MA2_UP")
          else plot4[PlotOffset2](Avg2,"MA2_DN");
end
else
begin  {***Plot previous values***}
     if  barnumber > Maxlist(MaLen1,MaLen2) then
     begin
          if Avg2[MoveLine2] > Avg2[Delay2+MoveLine2] 
               then plot3(Avg2[MoveLine2],"MA2_UP")
               else plot4(Avg2[MoveLine2],"MA2_DN");
     end;
end;

end;


